import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/dashboard.vue'
import Error from './views/404.vue'
import login from './views/login'
import store from './store.js'

let auth = localStorage.getItem('auth');
if (auth === 'undefined') {
    auth = '{}'
}
Vue.use(Router);

const router = new Router({
    routes: [
        {
            path: '/dashboard',
            meta: {
                needAuth: true, title:'首页'
            },
            name: 'dashboard',
            component: Home
        },
        {
            path: '/',
            meta: {
                needAuth: true
            },
            components: {
                login: login
            }
        },
        {
            path: '/sale-approval',
            component: () => import('./views/sale/approveQuest.vue')
        },
        {
            path: '/info-collect',
            component: () => import('./views/sale/infoCollect.vue')
        },
        {
            path: '/my-sale-approval',
            component: () => import('./views/sale/myApproval.vue')
        },
        {
            path: '/approve-sale-approval',
            component: () => import('./views/sale/approve.vue')
        },
        {
            path: '/sale-follow',
            component: () => import('./views/sale/saleContract.vue')
        },
        {
            path: '/my-contract',
            component: () => import('./views/sale/mySaleContract.vue')
        },
        {
            path: '/unit-quotation',
            component: () => import('./views/sale/unitQuotation.vue')
        },
        {
            path: '/part-quotation',
            component: () => import('./views/sale/partQuotation.vue')
        },
        {
            path: '/sales-order',
            component: () => import('./views/sale/salesOrder')
        },
        {
            path: '/sales-eva',
            component: () => import('./views/sale/saleContractEvaluation'),
            children: [
                {
                    path: 'list',
                    component: () => import('./views/sale/ContractEvaluationList'),
                    meta: {
                        needAuth: true
                    }
                },
                {
                    path: 'form',
                    component: () => import('./views/sale/ContractEvaluationForm'),
                    meta: {
                        needAuth: true
                    }
                },
                {
                    path: 'form/:id',
                    component: () => import('./views/sale/ContractEvaluationForm'),
                    meta: {
                        needAuth: true
                    }
                },
                {
                    path: '',
                    redirect: 'list'
                },
            ]

        },


        // purchase
        {
            path: '/vendor',
            component: () => import('./views/purchase/vendor.vue')
        },
        {
            path: '/purchase-request',
            component: () => import('./views/purchase/purchaseRequest')
        },
        {
            path: '/purchase-approve',
            component: () => import('./views/purchase/purchaseApprove')
        },
        {
            path: '/request-purchase',
            component: () => import('./views/purchase/requestPurchase')
        },
        {
            path: '/purchase-order',
            component: () => import('./views/purchase/purchaseOrder')
        },

        // export

        {
            path: '/export',
            meta:{ title : '进出口'},
            component: () => import('./views/export/export.vue')
        },
        // import
        {
            path: '/import',
            component: () => import('./views/export/import.vue')
        },

        // storck in
        {
            path: '/stock-in',
            component: () => import('./views/export/stockIn.vue')
        },
        {
            path: '/stock-in-list',
            component: () => import('./views/export/stockInList.vue')
        },

        // storage
        {
            path: '/storage',
            component: () => import('./views/export/storage.vue')
        },
        // stock out
        {
            path:'/mor/application',
            meta:{title:'出库申请'},
            component: () => import('./views/service/stockOutApplication')
        }, {
            path:'/weda/application',
            meta:{title:'出库申请'},
            component: () => import('./views/weda/stockOutApplication')
        }, {
            path:'/msk/application',
            meta:{title:'出库申请'},
            component: () => import('./views/msk/stockOutApplication')
        }, {
            path:'/tid/application',
            meta:{title:'出库申请'},
            component: () => import('./views/tid/stockOutApplication')
        },
        {
            path: '/stock-out',
            meta:{title:'出库'},
            component: () => import('./views/export/stockOut.vue')
        },
        //sparepart database
        {
            path: '/part-list',
            meta:{title:'物料数据'},
            component: () => import('./views/part/partlist')
        },
        {
            path: '/part-price',
            meta:{title:'物料价格'},
            component: () => import('./views/part/partPrice')
        },
        {
            path: '/fixed-part-price',
            meta:{title:'物料固定价格'},
            component: () => import('./views/part/fixedPartPrice')
        },
        {
            path: '/iec-part-list',
            meta:{title:'物料数据'},
            component: () => import('./views/part/iec-partlist')
        },
        {
            path: '/iec-part-price',
            meta:{title:'物料价格'},
            component: () => import('./views/part/iec-partPrice')
        },
        {
            path: '/part-stock',
            meta:{title:'库存汇总'},
            component: () => import('./views/part/partStock')
        },
        {
            path: '/extra/part',
            meta:{title:'合力配件'},
            component: () => import('./views/part/extraPart')
        },
        {
            path: '/heli/part-price',
            meta:{title:'合力配件价格'},
            component: () => import('./views/part/heliPartPrice')
        },
        {
            path:'/material-type',
            meta:{title:'物料类型'},
            component:() => import('./views/part/materialType')
        },
        //unit\
        {
            path: '/unit-type',
            component: () => import('./views/part/unitType')
        },
        {
            path: '/property',
            component: () => import('./views/part/property')
        },
        {
            path: '/unit-list',
            component: () => import('./views/part/unitlist')
        },
        {
            path: '/unit-field',
            component: () => import('./views/part/unitOptionType')
        },
        {
            path: '/unit-option',
            component: () => import('./views/part/unitOptionList')
        },
        //service

        {
            path: '/quest',
            meta:{title:'服务申请'},
            component: () => import('./views/service/quest')
        },
        {
            path: '/work-order',
            meta:{title:'工作单'},
            component: () => import('./views/service/workingOrder')
        },
        {
            path: '/service-stock-out',
            meta:{title:'寄售出库'},
            component: () => import('./views/service/stockOut')
        },
        {
            path: '/close-order',
            meta:{title:'结单'},
            component: () => import('./views/service/closeOrder')
        },
        {
            path: '/service-stock-in',
            meta:{title:'寄售入库'},
            component: () => import('./views/service/stockIn')
        },
        {
            path: '/service-report',
            meta:{title:'服务报告'},
            component: () => import('./views/service/report')
        },
        {
            path: '/service-report1',
            meta:{title:'服务统计'},
            component: () => import('./views/service/Order')
        },
        {
            path: '/service-equipment',
            meta:{title:'设备'},
            component: () => import('./views/service/equipment')
        },
        {
            path: '/service-project',
            meta:{title:'项目'},
            component: () => import('./views/service/project')
        },
        {
            path: '/point-code',
            meta:{title:'工时'},
            component: () => import('./views/service/pointCode')
        },
        {
            path: '/cost',
            meta:{title:'成本'},
            component: () => import('./views/service/cost')
        },
        {
            path: '/invoice',
            meta:{title:'发票'},
            component: () => import('./views/service/invoice')
        },
        {
            path:'/idr-invoice',
            meta:{title:'印尼盾发票'},
            component:() => import('./views/service/idr-invoice')
        },
        {
            path: '/inventory',
            meta:{title:'寄售在库'},
            component: () => import('./views/service/inventory')
        },
        //information
        {
            path:'/department',
            component:()=>import('./views/information/department')
        },
        {
            path:'/human',
            component:()=>import('./views/information/human')
        },
        {
            path: '/employee',
            component: () => import('./views/information/employee')
        },
        {
            path: '/customer',
            component: () => import('./views/information/customer')
        },
        {
            path: '/position-level',
            component: () => import('./views/information/positionLevel')
        },
        {
            path: '/work-board',
            component: () => import('./views/information/employeeWorkBoard')
        },
        {
            path: '/sys-customer',
            meta: {
                needAuth: true
            },
            component: () => import('./views/information/systemCustomer')
        },
        {
            path: '/warehouse',
            component: () => import('./views/information/warehouse')
        },
        //authority
        {
            path: '/user-manage',
            component: () => import('./views/auth/userManage')
        },
        {
            path: '/role-manage',
            component: () => import('./views/auth/roleManage')
        },
        {
            path: '/auth-manage',
            component: () => import('./views/auth/AuthManage')
        },
        {
            path: '/auth/module',
            component: () => import('./views/auth/module')
        },
        {
            path: '/auth/process',
            component: () => import('./views/auth/approveProcess')
        },

        //customer
        {
            path: '/customer-request',
            component: () => import('./views/customerQuest/purchaseRequest')
        },
        {
            path: '/customer-approve',
            component: () => import('./views/customerQuest/purchaseApprove')
        },
        //寄售合同 shanqi
        {
            path: '/shanqi/consignment',
            meta:{
                title:'寄售合同'
            },
            component: () => import('./views/consignment/consignment')
        },
        {
            path: '/shanqi/box',
            component: () => import('./views/shanxi/boxList')
        },
        {
            path: '/shanqi/export',
            component: () => import('./views/shanxi/export')
        },
        {
            path:'/shanqi/chart',
            component:()=>import('./views/shanxi/sale-chart')
        },
        // import
        {
            path: '/shanqi/import',
            component: () => import('./views/shanxi/import')
        },
        {
            path: '/shanqi/stockin',
            component: () => import('./views/shanxi/stockIn')
        },
        {
            path: '/shanqi/stockout',
            component: () => import('./views/shanxi/stockOut')
        },
        {
            path: '/shanqi/inventory',
            component: () => import('./views/shanxi/inventory')
        },
        {
            path: '/shanqi/delivery',
            component: () => import('./views/shanxi/delivery')
        },
        {
            path: '/shanqi/cost',
            component: () => import('./views/shanxi/cost')
        },
        {
            path: '/shanqi/statistic',
            component: () => import('./views/shanxi/statistic')
        },
        //jianzhan
        {
            path: '/jianzhan/purchase-request',
            component: () => import('./views/jianzhan/purchase')
        },
        {
            path: '/jianzhan/consignment',
            component: () => import('./views/jianzhan/consignment')
        },
        {
            path: '/jianzhan/delivery',
            component: () => import('./views/jianzhan/delivery')
        },
        {
            path: '/jianzhan/export',
            component: () => import('./views/jianzhan/export')
        },
        {
            path: '/jianzhan/vendor',
            component: () => import('./views/jianzhan/vendor')
        },
        {
            path: '/jianzhan/cost',
            component: () => import('./views/jianzhan/cost')
        },

        {
            path: '/weda/stock-out',
            component: () => import('./views/weda/stockOut')
        },
        {
            path: '/weda/stock-in',
            component: () => import('./views/weda/stockIn')
        },
        {
            path: '/weda/inv',
            component: () => import('./views/weda/invoice')
        },
        {
            path: '/weda/int',
            component: () => import('./views/weda/inventory')
        },
        {
            path:'/weda/idr-invoice',
            component:()=>import('./views/weda/idr-invoice')
        },
        {
            path: '/msk/stock-out',
            component: () => import('./views/msk/stockOut')
        },
        {
            path: '/msk/stock-in',
            component: () => import('./views/msk/stockIn')
        },
        {
            path: '/msk/inv',
            component: () => import('./views/msk/invoice')
        },
        {
            path: '/msk/int',
            component: () => import('./views/msk/inventory')
        },
        {
            path:'/msk/idr-invoice',
            component:() => import('./views/msk/idr-invoice')
        },
        //mor
        {
          path:'/mor/chart',
          component:() => import('./views/service/sale-chart')
        },
        //tid
        {
            path:'/tid/purchase',
            component: ()=> import('./views/tid/purchase')
        },
        {
            path:'/tid/wo-invoice',
            component:() => import('./views/service/woInvoice')
        },
        {
            path:'/backup',
            component:()=> import('./views/service/backup')
        },
        {
            path: '/tid/stock-out',
            component: () => import('./views/tid/stockOut')
        },
        {
            path: '/tid/stock-in',
            component: () => import('./views/tid/stockIn')
        },
        {
            path: '/tid/inv',
            component: () => import('./views/tid/invoice')
        },
        {
            path:'/tid/idr-invoice',
            component:() => import('./views/tid/idr-invoice')
        },
        {
            path: '/tid/int',
            component: () => import('./views/tid/inventory')
        },
        {
            path: '/tid/vendor',
            component: () => import('./views/tid/vendor')
        },
        {
            path:'/tids/oil',
            component: ()=> import('./views/TIDS/oil')
        },
        // 日报月报
        {
            path:'/iel/monthReport',
            component: () => import('./views/iel/monthReport')
        },
        {
            path:'/iel/dayReport',
            component: () => import('./views/iel/dayReport')
        },
        {
            path: "/log",
            component: () => import('./views/information/log')
        },
        {
            path: '/unAuth',
            meta: {
                needAuth: true
            },
            component: () => import('./views/unAuth')
        },

        {
            path: '*',
            component: Error
        }
    ]
});
router.beforeEach((to, from, next) => {
    let menu = store.state.auth && store.state.auth.menu && store.state.auth.menu.length ?
        store.state.auth.menu :
        JSON.parse(auth) && JSON.parse(auth).menu ? JSON.parse(auth).menu : [];
    if (menu.length || to.meta.needAuth) {
        if (to.meta.needAuth || menu.some(auth => auth.url === to.path)) {
            next();
        } else {
            next('/unAuth')
        }
    } else {
        next('/')
    }

});
export default router;
